class MrpWorkorder {
  String? id;
  String? userName;
  String? locationName;
  String? dateStart;
  String? state;
  String? mrpProductionId;

  MrpWorkorder({
    this.id,
    this.userName,
    this.locationName,
    this.dateStart,
    this.state,
    this.mrpProductionId,
  });

  MrpWorkorder copyWith({
    String? id,
    String? userName,
    String? locationName,
    String? dateStart,
    String? state,
  }) {
    return new MrpWorkorder(
      id: id ?? this.id,
      userName: userName ?? this.userName,
      locationName: locationName ?? this.locationName,
      dateStart: dateStart ?? this.dateStart,
      state: state ?? this.state,
    );
  }

  @override
  String toString() {
    return '''MrpWorkorder{
      id: id,
      userName: userName,
      locationName: locationName,
      dateStart: dateStart,
      state: state,
    }''';
  }

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      (other is MrpWorkorder &&
          runtimeType == other.runtimeType &&
          id == other.id);

  factory MrpWorkorder.fromMap(Map<String, dynamic> map) {
    return new MrpWorkorder(
      userName: map['name'] != false ? map['name'].toString() as String? : "",
      locationName: map['workcenter_id'] != false
          ? map['workcenter_id'][1].toString() as String?
          : "",
      dateStart: map['date_planned_start'] != false
          ? map['date_planned_start'].toString() as String?
          : "",
      state: map['state'] != false ? map['state'].toString() as String? : "",
    );
  }

  Map<String, dynamic> toMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'userName': this.userName,
      'station_id': this.locationName,
      'workshop_id': this.dateStart,
      'state': this.state,
    } as Map<String, dynamic>;
  }

  List toDomainList() {
    List list = [
      if (this.mrpProductionId != null && this.mrpProductionId != '')
        ['production_id', '=', int.parse(this.mrpProductionId!)],
    ] as List;
    // if (list.length == 0) {
    //   list.add(['id', '!=', null]);
    // }
    // ignore: unnecessary_cast
    return list;
  }
}
